/**
 * @author smallwang
 * @email justdoalitter@gmail.com
 * @create date 2025-02-09 16:01:41
 * @modify date 2025-02-09 16:01:41
 * @desc [description]
 */
package ltd.smallwang;

import ltd.smallwang.common.ListNode;

public class Leetcode0019 {
  public ListNode removeNthFromEnd(ListNode head, int n) {
    ListNode dummpy = new ListNode(-1);
    dummpy.next = head;
    ListNode fast = dummpy;
    ListNode slow = dummpy;
    for (int i = 0; i < n; i++) {
      fast = fast.next;
    }
    while (fast != null) {
      fast = fast.next;
      slow = slow.next;
    }
    if (slow.next != null) {
      slow.next = slow.next.next;
    }
    return dummpy.next;
  }
}
